-
Notifications
You must be signed in to change notification settings - Fork 0
/
Strong Password.c
85 lines (80 loc) · 2.25 KB
/
Strong Password.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @Repository HackerRank Soulutions
* @file Strong Password
* @author Abdelrahman Ahmed Moussa ([email protected])
* @copyright Copyright (c) 2024
*
*/
/*------------------------------------------------------------------------------*/
/* */
/* I didn't used any functions from <string.h> */
/* */
/*------------------------------------------------------------------------------*/
int minimumNumber(int n, char* password)
{
// Return the minimum number of characters to make the password strong
int remain_number;
int remain_ch=0;
int upper=0,lower=0,digit=0,ch=0;
char specialChar[]="!@#$%^&*()-=";
int i,j;
char breakFlag=1;
if (n<=6)
{
remain_number=6-n;
}
else
{
remain_number=0;
}
for (i=0; (i<n)&&(breakFlag) ;i++)
{
if (password[i]>='a' && password[i]<='z' && lower==0)
{
lower=1;
}
else if (password[i]>='A' && password[i]<='Z' && upper==0)
{
upper=1;
}
else if (password[i]>='0' && password[i]<='9' && digit==0)
{
digit=1;
}
/*else if (password[i]>='!' || password[i]<='@'||
password[i]<='#' || password[i]<='$'||
password[i]<='%' || password[i]<='^'||
password[i]<='&' || password[i]<='*'||
password[i]<='(' || password[i]<=')'||
password[i]<='-' || password[i]<='=' )
{
ch=1;
}*/
else if (ch==0)
{
j=0;
while (specialChar[j])
{
if (password[i]==specialChar[j])
{
ch=1;
}
j++;
}
}
if (lower && upper && digit && ch )
{
breakFlag=0;
}
}
remain_ch=4-(lower+upper+digit+ch);
if (remain_ch>remain_number)
{
return remain_ch;
}
else if (remain_ch<remain_number)
{
return remain_number;
}
return remain_ch;
}